/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package earleyalgorithm;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 *
 * @author NGOC
 */
public class WordCollection {
    private HashMap<String,Set<String>> wordClasses = new HashMap<String, Set<String>>();

    public void addWordClass(String word, String[] types){
        if(!wordClasses.containsKey(word)){
            Set s = new HashSet<String>();
            for(int i = 0; i < types.length; i++){
                if(!s.contains(types[i]))
                    s.add(types[i].toLowerCase());
            }
            wordClasses.put(word, s);
        }
    }


    public boolean isClass(String word, String type){
        Set types = wordClasses.get(word);
        if(types.contains(type))
            return true;
        return false;
    }

    public Set<String> getAllClasses(String word){
        return wordClasses.get(word);
    }

    @Override
    public String toString(){
        StringBuilder sb = new StringBuilder();
        Set<String> s = wordClasses.keySet();
        for(Iterator iter = s.iterator(); iter.hasNext();){
            String word = (String)iter.next();
            sb.append(word);
            sb.append("\t");
            Set<String> classes = wordClasses.get(word);
            for(Iterator it = classes.iterator(); it.hasNext();){
                String type = (String)it.next();
                sb.append(type);
                sb.append(" ");
            }
            sb.append("\n");
        }
        return sb.toString();
    }

    
}
